/-api
/-api/docs
/-api/storage
DocumentState.ts
LineAccess.ts
PropertyAccess.ts
Storage.ts
/-app ...
/-app/storage ...
/-app/storage/pluggable ...
/-app/storage/pluggable/localStorage ...
LocalStorage.ts
LocalStorageDocumentState.ts
LocalStorageImplementation.ts
LocalStoragePreloaded.ts
LocalStoragePropertyAccess.ts
GlobalStorage.ts
PluggableStorage.ts
PreloadedStorage.ts
PropertyKeyCache.ts
Application.ts
utils.ts
/-imports
/-typings
ko.ts
mark
sample-js.js
sample.html
sample.ts
schedule.ts
1
module teapo.app.storage.pluggable {
2
 
3
  export class LocalStorageImplementation implements Storage {
4
 
5
    private _editedKey: string;
6
    private _documentNamesKey: string;
7
 
8
    /**
9
     * Caching document names, with the side effect
10
     * that simultaneous access from multiple windows may race.
11
     */
12
    private _documentNames: string[] = null;
13
 
14
    globalProperties: PropertyAccess = null;
15
 
16
    constructor(
17
      private _localStorage,
18
      private _uniqueKey: string,
19
      populate: { edited: Date }) {
20
 
21
      this._editedKey = this._uniqueKey + '*edited';
22
      this._documentNamesKey = this._uniqueKey + '*documentNames';
23
 
24
      try {
25
        var edited = this._localStorage[this._editedKey];
26
        populate.edited = edited ? new Date(parseInt(edited)) : null;
27
      }
28
      catch (parseError) {
29
        populate.edited = null;
30
      }
31
    }
32
 
33
    documentNames(callback: (error: Error, names: string[]) => void) {
34
 
35
      if (!this._documentNames) {
36
        var documentNamesStr = this._localStorage[this._documentNamesKey];
37
 
38
        if (typeof documentNamesStr !== 'string')
39
          this._documentNames = [];
40
        else
41
          this._documentNames = documentNamesStr.split('\n');
42
      }
43
 
44
      callback(null, this._documentNames);
45
    }
46
 
47
    getDocument(fullPath: string, callback: (error: Error, docState: DocumentState) => void) {
48
      throw null;
49
    }
50
 
51
    removeDocument(fullPath: string, callback: (error: Error) => void) {
52
      throw null;
53
    }
54
 
55
    createDocument(fullPath: string, callback: (error: Error, docState: DocumentState) => void) {
56
      throw null;
57
    }
58
 
59
 
60
    loadMaster() {
61
      this.globalProperties = new LocalStoragePropertyAccess(this._localStorage, this._uniqueKey + '**');
62
    }
63
 
64
    loadSecondary(master: Storage, callback: (error: Error) => void) {
65
 
66
      // TODO: copy stuff from master
67
 
68
    }
69
  }
70
 
71
}